package algrs.jar;

import java.awt.Color;

public class VisualAccumulator {

private double total;
	private int N;
	public VisualAccumulator(int trials, double max) {
		StdDraw.setXscale(0, trials);
		StdDraw.setYscale(0, max);
		StdDraw.setPenRadius(.005);
	}
	public void addDataValue(double val) {
		++N;
		total += val;
		StdDraw.setPenColor(StdDraw.DARK_GRAY);
		
		StdDraw.point(N, val);
		StdDraw.setPenColor(StdDraw.RED);
		StdDraw.point(N, total/N);
	}
	public double mean() {
		return total/N;
	}
	public static void main(String[] args) {
		VisualAccumulator a = new VisualAccumulator(200, 50);
		for(int i = 1; i<2000; ++i)
			a.addDataValue(StdRandom.random());
	}

}
